package cn.com.xf.service.impl;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Date;

import org.springframework.web.multipart.MultipartFile;

import cn.com.xf.domain.TblCheckData;
import cn.com.xf.service.DataImportService;
import cn.com.xf.service.DataService;
import cn.com.xf.utils.DateUtils;
import cn.com.xf.web.XFContainsTool;

public class DataImportService1Impl implements DataImportService {

	private DataService dataService = (DataService) XFContainsTool.lookup("dataService");
	
	@Override
	public void importCheckData(MultipartFile file,String siteid, String entersite,
			String adduser) throws Exception {
		InputStream is = file.getInputStream();
        BufferedInputStream bis = null;
        InputStreamReader isr = null;
        BufferedReader br = null;
        bis = new BufferedInputStream(is);
        isr = new InputStreamReader(bis);  
        br = new BufferedReader(isr);
        String line;
        while ((line = br.readLine()) != null) {
        	String[] temp = line.split("\t");
        	String type = temp[3].trim();
        	String checktimeString = temp[1].trim();
        	String userid = siteid + temp[0].trim();
			Date checktime = DateUtils.parseDatetime(checktimeString);
			Date checkdate = DateUtils.parseDate(checktimeString);
			TblCheckData checkData = new TblCheckData();
			checkData.setSiteid(siteid);
			checkData.setEntersite(entersite);
			checkData.setEnteruser(adduser);
			checkData.setEntertime(new Date());
			checkData.setUserid(userid);
			checkData.setChecktime(checktime);
			checkData.setCheckdate(checkdate);
			checkData.setType(Short.valueOf(type));
			dataService.insertData(checkData);
        }
        is.close();
        bis.close();
        isr.close();
        br.close();
		
	}

}
